<?php

/**
 * Form for editing address data
 */
class Application_Form_Address extends Zend_Form_SubForm
{
    // Mapping keys to db columns
    private static $DB_MAPPING = array(
	"street" => "street",
	"house_num" => "housenumber",
	"city" => "city",
	"postalcode" => "postalcode",
    );
    
    // Mapping Max Length from db
    private static $MAX_LENGTH = array(
	"street" => "150",
	"house_num" => "15",
	"city" => "150",
	"postalcode" => "5"
    );
    
    public function init()
    {
	// Validators
	$postcode_own_valid = new Zend_Validate_Regex(array('pattern' => '/[0-9]/'));
	$postcode_own_valid->setMessage('%value% ist keine Postleitzahl. Erlaubte Zeichen: 0-9, 5 Stück. ');
	$valid_own_alphanum = new Zend_Validate_Regex(array('pattern' => '~^[a-zäöüß0-9]+([-, ][a-zäöüß0-9]+)*$~i'));
	$valid_own_alphanum->setMessage('%value% ist nicht Erlaubt. Erlaubte Zeichen: a-z,0-9, - , ');
	
	// Adress data Form Elements
	$this->addElement('text', $this::$DB_MAPPING['street'], array(
	    'label' => 'Strasse:',
	    'required' => false,
	    'filters' => array('StringTrim'),
	    'validators' => array(
		$valid_own_alphanum,
		array(
		    "StringLength",
		    false,
		    array(
			'max' => $this::$MAX_LENGTH['street'],
		))
		)));

	$this->addElement('text', $this::$DB_MAPPING['house_num'], array(
	    'label' => 'Hausnummer:',
	    'required' => false,
	    'filters' => array('StringTrim'),
	    'validators' => array(
		$valid_own_alphanum,
		array(
		    "StringLength",
		    false,
		    array(
			'max' => $this::$MAX_LENGTH['house_num'],
		)),
		)));

	//Postcode Valid dont work
	$this->addElement('text', $this::$DB_MAPPING['postalcode'], array(
	    'label' => 'Postleitzahl:',
	    'required' => false,
	    'filters' => array('StringTrim'),
	    'validators'=> array(
		'Int',$postcode_own_valid,
		    array(
		    "StringLength",
		    false,
		    array(
			'max' => $this::$MAX_LENGTH['postalcode'],
			'min' => $this::$MAX_LENGTH['postalcode'],
		)),
	)));

	$this->addElement('text', $this::$DB_MAPPING['city'], array(
	    'label' => 'Stadt:',
	    'required' => false,
	    'filters' => array('StringTrim'),
	    'validators' => array('Pos'),
	    'validators' => array(
		$valid_own_alphanum,
		array(
		    "StringLength",
		    false,
		    array(
			'max' => $this::$MAX_LENGTH['city'],
		)),
		)));
    }
    
}

?>
